<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
$lang =& JFactory::getLanguage();
?>

<h1 class="all_reward_header">
	<?php echo JTEXT::_('WRD_MYACCOUNT_POINT_SUMMARY')?>
</h1>

<div class="panel  panel-wmc">
  <div class="panel-heading">
    <h3 class="panel-title"><?php echo JText::_('WRD_PROFILE_ACCOUNT_PREFERENCE')?></h3>
  </div>
  <div class="panel-body">    
    <p><?php echo JTEXT::_('WRD_MYACCOUNT_MEMBER_NAME')?>:<br>
    <strong><?php echo  $this->profile->l_name.' '.$this->profile->f_name ?></strong></p>
    <p><?php echo JTEXT::_('WRD_MYACCOUNT_MEMBER_ID_ASSIGNED')?>:<br>
    <strong><?php echo  $this->profile->member_id; ?></strong></p>
    <p><?php echo JTEXT::_('WRD_MYACCOUNT_TOTAL')?>:<br>
        <strong><?php echo number_format($this->profile->p_o_u,0,'.',','); ?></strong>
    </p>
    
  </div>
</div>

<form role="form" id="show_point_range" name="show_point_range" method="post" action="<?php echo JRoute::_('index.php?option=com_wrd&view=profile&layout=myaccount&Itemid=119'); ?>" >
    <div class="form-group">
    <?php echo JHTML::_('wrd.listViewOptionFrontEnd','special_range',$this->special_range,'onchange="this.form.submit()"','form-control'); ?>
    </div>

	<div class="from-group">
		<div class="input-group">
            <span class="input-group-addon">
                <i class="fa fa-calendar"></i>
            </span>
            <input type="text" value="<?php echo $this->point_from_date ?>" id="point_from_date" name="point_from_date" type="text" class="form-control">
        </div>
    </div>
   <br clear="all">
    <div class="from-group">
		<div class="input-group">
            <span class="input-group-addon">
                <i class="fa fa-calendar"></i>
            </span>
            <input type="text" value="<?php echo $this->point_to_date ?>" id="point_to_date" name="point_to_date" type="text" class="form-control">
        </div>
    </div>	
    <br clear="all">
	<div class="form-group pull-right">
		<input class="date_submit btn btn-wmc" type="submit" name="show" value="<?php echo JText::_(WRD_MYACCOUNT_SHOW); ?>">
	</div>
	<br clear="all">
</form>
	

<?php
    if(count($this->level1)):
?>

       <?php foreach ($this->level1 as $raw=>$level1_item):
 
 			if($level1_item->type == 2)
				$sub = 0;
			elseif($level1_item->total > 1 || $level1_item->type == 0)
       			$sub = 1;
			elseif($level1_item->total == 1 && $level1_item->type == 9)
				$sub = 1;
			else
				$sub = 0;
            
            if($sub == 1):
       	 ?>       	
           	<div class="panel panel-wmc panel-point-wmc">
              <div class="panel-heading">
                <span class="numcol">
                    <?php echo date('d',strtotime($level1_item->created_date)); ?>
                    
                    <small><?php echo date('m/Y',strtotime($level1_item->created_date));?></small>
                </span>
                <span class="titlecol">
                    <?php echo $level1_item->des; ?>
                    <?php if($level1_item->type == 9)
                        echo '<br><small>'.$level1_item->redemption_id.'</small><br>'; ?>
                    <small>
                   
                    <?php if($level1_item->expire != '0000-00-00'): ?>
                        <?php if(strtotime($level1_item->expire) < time() && $level1_item->expire != '0000-00-00'):?>
                            <br><i>Point Expire on:<font color="#800000"><?php echo date('d/m/Y',strtotime($level1_item->expire));?></font></i>
                        <?php else: ?>
                           <br><i>Point Expire on: <?php echo date('d/m/Y',strtotime($level1_item->expire));?></i>
                        <?php endif; ?>
                    <?php endif; ?></small>
                </span>
                
                <span class="pull-right pointcol">
                    <?php if($level1_item->type == 9):?>-<?php endif; ?>
                    <?php if($level1_item->total == 1 && $level1_item->type != 9): ?>
                        <?php echo number_format($level1_item->point,0,'.',','); ?>
                    <?php else: ?>
                        <?php echo number_format($level1_item->sub_level2->total,0,'.',','); ?>
                    <?php endif;?>
                </span>
              </div>
            <?php endif; ?>  
       	
       	<?php if($sub == 1 && $level1_item->type == 1): ?>
       	    <table class="table table-striped">
       	        <tbody>
               		<?php foreach ($level1_item->sub_level2->level2 as $sub_level2): ?>
                   		<tr class="subtop_<?php echo $level1_item->type ?>_<?php echo $raw; ?>">
            	       		<td class="td-title">
            	       			<?php echo JText::_(WrdHelper::stringURLSafeAliasLang('WRD_MYACCOUNT_'.$sub_level2->des)); ?>
            	       			
            	       		</td>
            	       		<td class="td-point">
            	       			<?php echo number_format($sub_level2->point,0,'.',','); ?>
            	       		</td>
            	       		
            	       	</tr>
               		<?php endforeach; ?>
       		   </tbody>
       		 </table>
       		</div>
       	<?php endif; ?>
       	
       	
       	<?php if($sub == 1 && $level1_item->type == 0): ?>
	       		<table class="table table-striped">
	       			<tbody>
	       				<?php foreach ($level1_item->sub_level2->level2 as $sub_level2): ?>
	       					<tr>
	       						<td class="td-title">
	       							<?php echo $sub_level2->outlet_name; ?>
	       						</td>
	       						<td class="td-point">
	       							<?php echo number_format($sub_level2->point,0,',',',') ; ?>
	       						</td>
	       					</tr>
	       				<?php endforeach;?>
	       			</tbody>
	       		</table>
       		</div>
       	<?php endif; ?>
       	
       	
		<?php if($sub == 1 && $level1_item->type == 9): ?>
		    <table class="table table-striped">
                <tbody>
                    <?php foreach ($level1_item->sub_level2->level2 as $sub_level2): ?>
                        <tr>
                            <td class="td-title">
                                <?php 
                                $product_name = unserialize($sub_level2->product_name);
                                echo $product_name[$lang->getTag()]; 

                                ?>
                            </td>
                            <td class="td-point">
                                -<?php echo number_format($sub_level2->point,0,'.',',') ; ?>
                            </td>
                        </tr>
                        <?php endforeach;?>
                    </tbody>
               </table>
           </div>
       	<?php endif; ?>
       <?php endforeach; ?>
<?php 
   else:
?>
<p class="help-block">Empty</p>
<?php endif; ?>
